home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char *RCSntp = "$Header: ntp.h,v 2.7 89/02/19 16:08:33 bww Exp $";
- #endif
-
- /*
- ****************************************************************
- * HISTORY
- * $Log: ntp.h,v $
- * Revision 2.7 89/02/19 16:08:33 bww
- * SSP headers.
- * [89/02/19 16:06:13 bww]
- *
- * Revision 2.6 88/11/11 16:06:58 bww
- * Upgraded to latest UMD release.
- *
- * Revision 2.5 88/09/20 21:59:13 bww
- * Added support for hashed peer list.
- *
- * Revision 2.4 88/08/30 18:29:41 bww
- * Let's try a 256ms SET_THRESHOLD.
- *
- * Revision 2.3 88/08/20 19:07:20 bww
- * Allowance for flaky UNIX time on Suns.
- *
- * Revision 2.2 88/07/28 18:42:31 bww
- * First CMUCS release
- *
- * Revision 2.1 88/04/25 18:00:36 root
- * Initial CMU revision
- *
- * Revision 2.1 88/04/25 18:00:36 root
- * *** empty log message ***
- *
- * Revision 2.0 88/03/31 10:25:06 root
- * *** empty log message ***
- *
- * Revision 1.2 88/02/28 22:59:25 petry
- * *** empty log message ***
- *
- * Revision 1.1 87/12/16 10:33:07 root
- * Initial revision
- *
- */
-
- /* b_32 from MacTCP commontypes */
- #define u_long b_32
- #define u_short b_16
- #define u_char b_8
- #define u_int b_16
-
- #define htonl(a) (a)
- #define ntohl(a) (a)
- #define ntohs(a) (a)
-
- /* the clock in the mac is in seconds since
- * Jan 1 1904.
- * timeval's are expected on the mac to hold
- * the time in seconds + microseconds of
- * GMT since Jan 1, 1970.
- */
-
- struct timeval {
- time_t tv_sec;
- time_t tv_usec;
- };
-
- struct timezone {
- int tz_minuteswest;
- int tz_dsttime;
- };
-
- struct intf {
- int fd;
- char *name;
- StreamPtr sin;
- StreamPtr bcast;
- int uses;
- int if_flags;
- };
-
- /*
- * Definitions for the masses
- */
- #define MAXNAMELENGTH 80
- #define JAN_1970 2208988800 /* 1970 - 1900 in seconds */
- #define HIGH_BIT 0x80000000 /* sign bit on fixed point */
-
- /*
- * User program specific (ntp.c)
- */
- #define RETRY_COUNT 2 /* number of times we want to retry */
- #define TIME_OUT 60 /* time to wait for reply, in secs */
-
- /*
- * Daemon specific (ntpd.c)
- */
- #define SAMPLES 8 /* number of samples for 1st order filter */
- #define SHIFT_MASK 0xff /* number of intervals to wait */
- #define WAYTOOBIG 1000.0 /* Too many seconds to correct, something is
- * really wrong */
- #define SET_THRESHOLD 0.128 /* Threshold for using settimeofday */
-
- #define NTPINITFILE "ntp.conf"
-
- /*
- * Definitions outlined in the NTP spec
- */
- #define NTP_VERSION 1
- #define NTP_PORT 123 /* for ref only (see /etc/services) */
- #define NTP_MINPOLL 6 /* (64) seconds between messages */
- #define NTP_MAXPOLL 10 /* (1024) secs to poll */
- #define NTP_GRANPOLL 5 /* Granularity of poll intervals in seconds */
- #define NTP_MAXDISP 65.5360 /* Maximum dispersion */
- #define PEER_SHIFT 8 /* size of shift register */
- #define PEER_THRESHOLD .500 /* dispersion threshold */
- #define PEER_FILTER .5 /* filter weight */
- #define PEER_SELECT .75 /* select weight */
-
- #define NTP_MAXDELAY 65536.0 /* Maximum dispersion seconds*/
-
- /*
- * Structure definitions for NTP fixed point values
- *
- * 0 1 2 3
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Integer Part |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Fraction Part |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
- * 0 1 2 3
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Integer Part | Fraction Part |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- struct l_fixedpt {
- u_long int_part;
- u_long fraction;
- };
-
- struct s_fixedpt {
- u_short sint_part;
- u_short sfraction;
- };
- /*
- * NTP packet definitions
- *
- * 0 1 2 3
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * |LI | VN |0 0 0| Stratum | Poll | Precision |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Synchronizing Distance |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Estimated Drift Rate |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Reference Clock Identifier |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | |
- * | Reference Timestamp (64 bits) |
- * | |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | |
- * | Originate Timestamp (64 bits) |
- * | |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | |
- * | Receive Timestamp (64 bits) |
- * | |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | |
- * | Transmit Timestamp (64 bits) |
- * | |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- struct ntpdata {
- u_char status; /* status of local clock and leap info */
- u_char stratum; /* Stratum level */
- u_char poll; /* poll value */
- char precision;
- struct s_fixedpt distance;
- u_long drift;
- u_long refid;
- struct l_fixedpt reftime;
- struct l_fixedpt org;
- struct l_fixedpt rec;
- struct l_fixedpt xmt;
- };
- /*
- * Leap Second Codes (high order two bits)
- */
- #define NO_WARNING 0x00 /* no warning */
- #define PLUS_SEC 0x40 /* add a second (61 seconds) */
- #define MINUS_SEC 0x80 /* minus a second (59 seconds) */
- #define ALARM 0xc0 /* alarm condition (clock unsynchronized) */
-
- /*
- * Clock Status Bits that Encode Version
- */
- #define NTPVERSION_1 0x08
- #define VERSIONMASK 0x38
- #define LEAPMASK 0xc0
-
- /*
- * Stratum Definitions
- */
- #define UNSPECIFIED 0
- #define PRIM_REF 1 /* radio clock */
- #define MAXSTRATUM 60
- #define INFO_QUERY 62 /* **** THIS implementation dependent **** */
- #define INFO_REPLY 63 /* **** THIS implementation dependent **** */
-
- #define ACTIVE 0x01 /* opposite of PASSIVE */
- #define MEDIAN 0x02
-
- /*
- * Structure of the per peer variables
- */
- struct ntp_peer {
- struct ntp_peer *next_peer;
- struct ntp_peer *next_hash;
- ip_addr src;
- ip_port port;
- int sock;
- u_long state;
- u_long reach;
- u_long timer;
- u_long threshold;
- u_char leap;
- u_char stratum;
- u_char ppoll;
- u_char hpoll;
-
- struct s_fixedpt distance;
- char precision;
- u_long drift;
- u_long refid;
- struct l_fixedpt reftime;
- /*
- * first order offsets
- */
- struct filter {
- short index;
- double offset[SAMPLES];
- double delay[SAMPLES];
- } filter;
- double delay;
- double offset;
- double dispersion;
-
- struct l_fixedpt rec;
- struct l_fixedpt org;
- u_long pkt_sent;
- u_long pkt_rcvd;
- };
-
- struct select_list {
- struct ntp_peer *peer;
- u_short sort_item;
- double dsp;
- };
-
- /*
- * These structures are used to pass information to the ntpdc (control)
- * program. They are unique to this implementation and not part of the
- * NTP specification.
- */
- struct clockinfo {
- u_long net_address;
- u_long my_address;
- u_short port;
- u_short flags;
- u_long pkt_sent;
- u_long pkt_rcvd;
- u_long timer;
- long threshold;
-
- u_char leap;
- u_char stratum;
- u_char ppoll;
- char precision;
-
- u_char hpoll;
- u_char reach;
- u_short filler;
-
- u_long drift;
- u_long refid;
- struct l_fixedpt reftime;
- struct info_filter {
- short index;
- short filler;
- struct l_fixedpt offset[SAMPLES];
- struct l_fixedpt delay[SAMPLES];
- } info_filter;
- };
-
- struct ntpinfo {
- char filler;
- u_char type; /* request type (stratum in ntp packets) */
- u_short count; /* pad to 32-bit boundary */
- struct clockinfo clocks[1];
- };
-
- struct sysdata {
- struct s_fixedpt distance;
- u_long drift;
- u_long refid;
- struct l_fixedpt reftime;
- struct ntp_peer *peer;
- int maxpeers;
- u_char leap;
- u_char stratum;
- char precision;
- u_char filler; /* put here for %&*%$$ SUNs */
- };
-